﻿using System;
using System.Globalization;
using System.Linq;
using System.Web.UI;

namespace TheheVn
{
    public partial class UcCustomHtml : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    string query = Request.Url.LocalPath.Trim('/');
                    bool isvn = query.StartsWith("e");
                    query = query.TrimStart('e');
                    if (!query.StartsWith("Sub", true, CultureInfo.InvariantCulture))
                    {
                        using (var ent = new Entities())
                        {
                            HtmlData data = ent.HtmlDatas.FirstOrDefault(p => p.Type == query);
                            if (data == null) return;
                            inner_html.InnerHtml = isvn ? data.EnHtmlText : data.VnHtmlText;
                        }
                    }

                    else
                    {
                        if (Request.QueryString["id"] == null) return;

                        int id = Convert.ToInt32(Request.QueryString["id"]);
                        using (var ent = new Entities())
                        {
                            HtmlData data = ent.HtmlDatas.FirstOrDefault(p => p.Type == query && p.Id == id);
                            if (data == null) return;
                            inner_html.InnerHtml = isvn ? data.EnHtmlText : data.VnHtmlText;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
    }
}